﻿'''
    course.py
        
        The course.py module contains two classes, 'course' and
        'student_course', that contain methods and data relevant
        to the courses that are in the UMBC course database.

        class course
      
            Class 'course' is used to objectify a course from UMBC's
            database. It initializes a course for use in the application
            with all of its relevant attributes and methods.

        class student_course
      
            Class 'student_course' uses class course to collect courses
            that a student added to his/her graduation plan while also adding
            course grade and the semester and year that the course is
            planned to be taken.
'''

'''
    course

    Class 'course' is used to objectify a course from UMBC's
    database. It initializes a course for use in the application
    with all of its relevant attributes and methods.
'''
class course:
    
    '''
        __init__()
       
        Initializes a course with all of its relevant
        information: id, title, department, credits, etc.
    '''
    def __init__(self, course_info):
        self._id, self._title, self._department, self._credits, \
        self._description, self._prereqs, self._gep_types, \
        self._minor_fulfillments = course_info
        
        self._attributes = course_info
        
    '''
        contains_searchterm()
       
        Checks if the passed in term is contained in
        class attributes
    '''
    def contains_searchterm(self, term):
        for field in self._attributes:
            if term.upper() in str(field).upper():
                return True
        return False
        
    '''
        get_prerequisites()
       
        Returns the course's prerequisites
    '''
    def get_prerequisites(self):
        my_prereqs = []
        for course in self._prereqs:
            my_prereqs.append(course)
        return my_prereqs
    
    '''
        is_prerequisite()

        Checks if the course is a prerequisite
    '''
    def is_prerequisite(self, coursename):
        return coursename in self._prereqs
    
    '''
        get_name()
        
        Returns course name
    '''
    def get_name(self):
        name = self._title
        return name
    
    '''
        get_id()
       
        Returns course id
    '''
    def get_id(self):
        return self._id
    
    '''
        is_named()
       
        **description here**
    '''
    def is_named(self, name):
        return name == self._id
    
    '''
        get_description()
        
        Returns all the relevant information about
        a course in a string
    '''
    def get_description(self):
        description = self._id + '\t(' + str(self._credits) + ' credits)\n'
        description += self._title +  '\n'
        description += self._description
        return description
    
    '''
        display_string()

        Returns a string with course id, credits and title 
    '''
    def display_string(self):
        return self._id + '\t' +  str(self._credits) + '\n' +  self._title
        
    '''
        get_credits()
        
        Returns the credits of the course.
    '''
    def get_credits(self):
        return self._credits
 
'''
    student_course

    Class student_course uses class course to collect courses
    that a student added to his/her graduation plan while also adding
    course grade and the semester and year that the course is
    planned to be taken.
'''   
class student_course:
    
    '''
        __init__()
       
        Initializes a course that the student has in
        the plan
    '''
    def __init__(self, course, semester, grade):
        self._course = course
        self._semester = semester
        self._grade = grade

    '''
        get_credits()
        
        Returns the credits of the course.
    '''
    def get_credits(self):
        return self._course.get_credits()
        
    '''
        change_grade()
       
        Changes course grade to the passed in grade
    '''
    def change_grade(self, grade):
        self._grade = grade
        
    '''
        get_grade()
       
        Returns course grade
    '''
    def get_grade(self):
        return self._grade
    
    '''
        set_grade()
       
        **Sets course grade to the passed in grade;
        looks the same as change_grade() and yet
        when removed makes changing grade impossible**
   '''
    def set_grade(self, grade):
        self._grade = grade

    '''
        get_semester()
       
        Returns a particular semester of the plan
    '''
    def get_semester(self):
        return self._semester
    
    '''
        get_name()
       
        Returns course name
    '''
    def get_name(self):
        return self._course.get_name()
    
    '''
        get_prerequisites() 
       
        Returns course prerequisites
    '''
    def get_prerequisites(self):
        return self._course.get_prerequisites()
    
    '''
        is_prerequisite()
       
        Checks if the course is a prerequisite
    '''
    def is_prerequisite(self, coursename):
        return self._course.is_prerequisite()
    
    '''
        is_named()
       
        **description here**
    '''
    def is_named(self, name):
        return self._course.is_named(name)
    
    '''
        get_id()
       
        Returns course id
    ''' 
    def get_id(self):
        return self._course.get_id()

    '''
        display_string()
       
        Returns a string with the course id, credits, title
        and grade
    '''
    def display_string(self):
        return self._course.display_string() + '\n' + "Grade: " + self._grade
